//
//  UILabel+GEE_fastInit.m
//  KX11UI
//
//  Created by HYC on 2021/2/20.
//

#import "UILabel+Tools_HYC_Neusoft.h"
#import "NSString+Tools_HYC_Neusoft.h"




@implementation UILabel (Tools_HYC_Neusoft)

- (UILabel *(^)(CGRect T)) H_frame {
    return ^id(CGRect T){
        self.frame = T;
        return self;
        };
}
- (UILabel *(^)(NSString * T)) H_text {
    return ^id(NSString * T){
        self.text = T;
        return self;
        };
}
- (UILabel *(^)(UIFont *T)) H_Font; {

    return ^id(UIFont *T){
        self.font = T;
        return self;
        };
}
- (UILabel *(^)(UIColor * T)) H_textColor {
    
    return ^id(UIColor * T){
        self.textColor = T;
        return self;
        };
}
- (UILabel *(^)(UIColor * T)) H_backgroundColor {
    
    return ^id(UIColor * T){
        self.backgroundColor = T;
        return self;
        };
}
- (UILabel *(^)(NSString * T)) H_textColorStr {
    return ^id(NSString * T){
        self.textColor = T.color;
        return self;
        };
}
- (UILabel *(^)(NSInteger T)) H_numberOfLines {
    
    return ^id(NSInteger T){
        self.numberOfLines = T;
        return self;
        };
}
- (UILabel *(^)(NSTextAlignment T)) H_textAlignment {
    
    return ^id(NSTextAlignment T){
        self.textAlignment = T;
        return self;
        };
}


/// 跑马灯Label
- (UILabel *)Running {
    UILabel *label3 = self;
//    label3.font = ZLVH_GEE_FONTSIZE(12);
    label3.frame = CGRectMake(label3.frame.origin.x,
                              label3.frame.origin.y,
                              [self.text boundingRectWithSize:CGSizeMake(MAXFLOAT, 30) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self.font} context:nil].size.width,
                              label3.frame.size.height
                              );
    if (label3.frame.size.width <= self.frame.size.width) return label3;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        CGRect frame = label3.frame;
        frame.origin.x = 0;
        label3.frame = frame;
        [UIView beginAnimations:@"testAnimation"context:NULL];
        [UIView setAnimationDuration:13.8f];//速度
        [UIView setAnimationCurve:UIViewAnimationCurveLinear];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationRepeatAutoreverses:NO];
        [UIView setAnimationRepeatCount:MAXFLOAT];
        frame = label3.frame;
        
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 // 当前Xcode支持iOS8及以上
        frame.origin.x =-frame.size.width + ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)]?[UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale:[UIScreen mainScreen].bounds.size.width) - 40;
#else
        frame.origin.x =-frame.size.width + [UIScreen mainScreen].bounds.size.width - 40;
#endif
        label3.frame = frame;
        [UIView commitAnimations];
        
    });
    return label3;
}

@end
